package ua.kharkov.knure.mikhaylov.st4.web.command;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;

import ua.kharkov.knure.mikhaylov.st4.db.entities.Account;
import ua.kharkov.knure.mikhaylov.st4.db.management.DBManager;
import ua.kharkov.knure.mikhaylov.st4.settings.Path;

/**
 * Command - browse blocked accounts
 * 
 * @author Saint
 * 
 */
public class BrowseBlockedAccountsCommand extends Command {

	private static final long serialVersionUID = -6734233708399160949L;
	private static final Logger log = Logger
			.getLogger(BrowseBlockedAccountsCommand.class);

	@Override
	public String execute(HttpServletRequest request,
			HttpServletResponse response) throws IOException, ServletException {

		log.debug("Command starts");

		HttpSession session = request.getSession();

		log.trace("Getting blocked accounts");

		List<Account> accounts = DBManager.getInstance().findAccountsBlocked();

		log.trace("Number of blocked accounts --> " + accounts.size());

		session.setAttribute("accounts", accounts);

		log.debug("Blocked accounts extracted");

		log.debug("Command finished");
		return Path.PAGE_BLOCKED_ACCOUNTS;
	}

}
